#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
int main(){
	pid_t ret;
	int status , i;
	int role = -1;
	ret = fork();
	if(ret > 0){
		// 对于父进程而言：
		//返回了正常的子进程ID
		printf("我是父进程，我的信息：（pid %d）\n",getpid());
		printf("我的父进程ID：%d\n", getppid());
		for(i=0;i<6;i++){
			printf("Parent: At count %d\n", i);
			sleep(1);  
			    }
		ret = wait(&status);
		printf("status为：%d\n",status);
		//防止僵尸进程的产生
		role=0;  
		    }
	else
		if(ret == 0){
			// 对于子进程而言
			printf("我是子进程，我的信息：(pid %d)\n", getpid());
			printf("我的父进程ID：%d\n", getppid());
			for(i=0;i<6;i++){
				printf("Chile: At count %d\n",i);
				sleep(1);       
			}
			role = 1;        
		}
		else{
			printf("Parent: Error trying to fork() (%d)\n", errno);
		}
printf("%s: Exiting...\n", ((role ==0)?"Parent":"Child"));
		return 0;
}
	
